//
// Created by Jisam on 2024/8/17 19:47.
// Solution of  b
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>

using namespace std;

#define endl "\n"
#define PSI pair<string,int>
#define PII pair<int,int>
#define PDI pair<double,int>
#define PDD pair<double,double>
#define VVI vector<vector<int>>
#define VI vector<int>
#define VS vector<string>

#define PQLI priority_queue<int, vector<int>, less<int>>
#define PQGI priority_queue<int, vector<int>, greater<int>>
#define ui unsigned
#define lli long long
#define ulli unsigned long long
#define code_by_jisam ios::sync_with_stdio(false),cin.tie(nullptr)
using namespace std;


void solution() {
    int a,b;
    cin >> a >>b;
    int t = gcd(a,b);
    lli ans = 1;
    for(int i = 2 ; i * i <= t; i ++)
    {
        if(t % i != 0) continue;
        int cnt = 0;
        while (t % i == 0) {
            ++cnt;
            t /= i;
        }
        ans *= cnt + 1;

    }
    if (t > 1) {
        ans *= 2;
    }
    cout << ans << "\n";
}

int main() {
    code_by_jisam;
    int T = 1;
    cin >> T;
    while (T--) {
        solution();
    }
    return 0;
}